package org.veloxbot.api.utils;

/**
 * @author iJava
 */
public class Random {

	private static final java.util.Random random = new java.util.Random();

	/**
	 * Generates a random integer within specified range.
	 *
	 * @param min The minimum number to be generated
	 * @param max The maximum number to be generated
	 * @return The generated random integer
	 */
	public static int nextInt(int min, int max) {
		if (min > max) {
			int minT = min;
			min = max;
			max = minT;
		}
		if (min == max) {
			return min;
		}
		return min + (int) (Math.random() * ((max - min) + 1));
	}

	/**
	 * Generates a random double within specified range.
	 *
	 * @param min The minimum number to be generated
	 * @param max The maximum number to be generated
	 * @return The generated random double
	 */
	public static double nextDouble(double min, double max) {
		if (min > max) {
			double minT = min;
			min = max;
			max = minT;
		}
		if (min == max) {
			return min;
		}
		return min + (Math.random() * (max - min));
	}

	/**
	 * Generates a random float within specified range.
	 *
	 * @param min The minimum number to be generated
	 * @param max The maximum number to be generated
	 * @return The generated random float
	 */
	public static float nextFloat(float min, float max) {
		if (min > max) {
			float minT = min;
			min = max;
			max = minT;
		}
		if (min == max) {
			return min;
		}
		return min + random.nextFloat() * (max - min);
	}

	/**
	 * @param min       The minimum number to be generated
	 * @param max       The maximum number to be generated
	 * @param average   The average
	 * @param deviation The standard deviation
	 * @return The generated random integer
	 */
	public static int nextGaussian(int min, int max, final int average, final int deviation) {
		if (min > max) {
			int minT = min;
			min = max;
			max = minT;
		}
		if (min == max) {
			return min;
		}
		int gaussian = (int) (random.nextGaussian() * deviation + average);
		return (gaussian >= min && gaussian <= max ? gaussian : min);
	}

	/**
	 * Generates a random long
	 *
	 * @param min The minimum number to be generated
	 * @param max The maximum number to be generated
	 * @return The generated random long
	 */
	public static long nextLong(long min, long max) {
		if (min > max) {
			long minT = min;
			min = max;
			max = minT;
		}
		if (min == max) {
			return min;
		}
		return min + random.nextLong() * (max - min);
	}

	/**
	 * Generates a random gaussian
	 *
	 * @return The generated random integer
	 */
	public static int nextGaussian() {
		return (int) random.nextGaussian();
	}

	/**
	 * Generates a random boolean value
	 *
	 * @return The generated random boolean
	 */
	public static boolean nextBoolean() {
		return random.nextBoolean();
	}

	/**
	 * Generates a random double
	 *
	 * @return The generated random double
	 */
	public static double nextDouble() {
		return random.nextDouble();
	}

	/**
	 * Generates a random integer
	 *
	 * @return The generated random integer
	 */
	public static int nextInt() {
		return random.nextInt();
	}

	/**
	 * Generates a random float
	 *
	 * @return The generated random float
	 */
	public static float nextFloat() {
		return random.nextFloat();
	}

	/**
	 * Generates a random long
	 *
	 * @return The generated random long
	 */
	public static long nextLong() {
		return random.nextLong();
	}
}


